<?php
namespace Tbf\Bundle\SerializerBundle\Tests;
use Symfony\Component\DependencyInjection\Container;
use Tbf\Bundle\SerializerBundle\Handler\HandlerRegistry;
use Tbf\Bundle\SerializerBundle\Register\Register;
use Tbf\Bundle\SerializerBundle\Serializer;

class SerializerTest extends TbfSerializerTestCase
{
    public function testToArray()
    {
        $serializer = $this->getSerializer();
        $ret = $serializer->toArray(new C1());
        $this->assertEquals(array('a'=>'b','b'=>'d'),$ret);
    }
    public function testLoadFromArray()
    {
        $obj = new C1();
        $serializer = $this->getSerializer();
        $serializer->loadFromArray($obj,array('b'=>'a'));
        $this->assertEquals('a',$this->getValue($obj,'b'));
    }
    public function testNewFromArray()
    {
        $obj = new C1();
        $serializer = $this->getSerializer();
        $ret_obj = $serializer->newFromArray(get_class($obj),array('b'=>'a'));
        $this->assertEquals('a',$this->getValue($ret_obj,'b'));
        $this->assertEquals('b',$this->getValue($ret_obj,'a'));
    }
    protected function getValue($obj,$property_name)
    {
        $meta_property = new \ReflectionProperty(get_class($obj),$property_name);
        $meta_property->setAccessible(true);

        return $meta_property->getValue($obj);
    }
    protected function getSerializer()
    {
        return new Serializer(new Register(new Container()));
    }
}
class C1
{
    protected $a='b';
    private $b='d';
}
class C1SerializeHandler
{
    protected $a;
}
